package com.rongc.client.freight.business.supply.view.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory;
import android.view.View;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.BitmapImageViewTarget;
import com.rongc.client.freight.ApiUrl;
import com.rongc.client.freight.R;
import com.rongc.client.freight.base.view.adapter.RecyclerBaseAdapter;
import com.rongc.client.freight.business.supply.model.CommentBean;

import java.util.List;

/**
 * Created by ccqx on 2017/7/15.
 */

public class RecyclerSupplyCommentAdapter extends RecyclerBaseAdapter<CommentBean>{


    public RecyclerSupplyCommentAdapter(Context mContext, List<CommentBean> mDatas) {
        super(mContext, mDatas);
    }

    @Override
    protected void onBind(final BaseRecyclerViewHolder holder, int position, CommentBean data) {
        holder.getImageView(R.id.iv_head).setVisibility(View.VISIBLE);
        Glide.with(mContext.getApplicationContext())
                .load(ApiUrl.getImgUrl(data.getImg()))
                .asBitmap()
                .centerCrop()
                .placeholder(R.mipmap.universal_head_default)
                .into(new BitmapImageViewTarget(holder.getImageView(R.id.iv_head)) {
                    @Override
                    protected void setResource(Bitmap resource) {
                        RoundedBitmapDrawable roundedBitmapDrawable =
                                RoundedBitmapDrawableFactory.create(mContext.getResources(), resource);
                        roundedBitmapDrawable.setCircular(true);
//                                        roundedBitmapDrawable.setCornerRadius(20); //设置圆角半径（根据实际需求）
                        roundedBitmapDrawable.setAntiAlias(true); //设置反走样
                        getView().setImageDrawable(roundedBitmapDrawable);
                    }
                });


        holder.setText(R.id.tv_name,data.getNick());
        holder.setText(R.id.tv_date,data.getCreatetime());
        holder.setText(R.id.tv_content,data.getContents());

    }

    @Override
    protected int getLayoutId() {
        return R.layout.recycler_comment_item;
    }
}
